<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-if="formThead.id" v-model="listQuery.id" style="width: 200px;" class="filter-item" placeholder="id" @keyup.enter.native="handleFilter"/>
      <el-input v-if="formThead.merchantName" v-model="listQuery.merchantName" style="width: 200px;" class="filter-item" placeholder="商家名称" @keyup.enter.native="handleFilter"/>
      <el-input v-if="formThead.adminAccount" v-model="listQuery.adminAccount" style="width: 200px;" class="filter-item" placeholder="后台账号" @keyup.enter.native="handleFilter"/>
      <el-input v-if="formThead.adminPassword" v-model="listQuery.adminPassword" style="width: 200px;" class="filter-item" placeholder="后台密码" @keyup.enter.native="handleFilter"/>
      <el-input v-if="formThead.auditStatus" v-model="listQuery.auditStatus" style="width: 200px;" class="filter-item" placeholder="审核状态" @keyup.enter.native="handleFilter"/>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
      <addPage @getLists="getLists"/>
    </div>

    <div class="filter-container">
      <el-checkbox v-model="formThead.id" label="id">id</el-checkbox>
      <el-checkbox v-model="formThead.merchantName" label="商家名称">商家名称</el-checkbox>
      <el-checkbox v-model="formThead.adminAccount" label="后台账号">后台账号</el-checkbox>
      <el-checkbox v-model="formThead.adminPassword" label="后台密码">后台密码</el-checkbox>
      <el-checkbox v-model="formThead.auditStatus" label="审核状态">审核状态</el-checkbox>
    </div>

    <el-table v-loading="listLoading" :key="tableKey" :data="list" border fit highlight-current-row style="width: 100%;">
      <el-table-column v-if="formThead.id" align="center" label="id">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column v-if="formThead.merchantName" align="center" label="商家名称">
        <template slot-scope="scope">
          <span>{{ scope.row.merchantName }}</span>
        </template>
      </el-table-column>
      <el-table-column v-if="formThead.adminAccount" align="center" label="后台账号">
        <template slot-scope="scope">
          <span>{{ scope.row.adminAccount }}</span>
        </template>
      </el-table-column>
      <el-table-column v-if="formThead.adminPassword" align="center" label="后台密码">
        <template slot-scope="scope">
          <span>{{ scope.row.adminPassword }}</span>
        </template>
      </el-table-column>
      <!--<el-table-column v-if="formThead.paymentCode" align="center" label="支付密码">-->
      <!--<template slot-scope="scope">-->
      <!--<span>{{ scope.row.paymentCode }}</span>-->
      <!--</template>-->
      <!--</el-table-column>-->
      <el-table-column v-if="formThead.auditStatus" align="center" label="审核状态">
        <template slot-scope="scope">
          <el-button v-if="scope.row.auditStatus==='Y'" type="success" size="small" icon="el-icon-check" circle title="已通过" @click="forbidden(scope.row.id)"/>
          <!--<el-button v-else-if="scope.row.status===1" type="success" size="small" icon="el-icon-check" circle title="预约成功"/>-->
          <!--<el-button v-else-if="scope.row.status===2" type="info" size="small" icon="el-icon-check" circle title="到诊"/>-->
          <el-button v-else type="info" size="small" icon="el-icon-close" circle title="未通过" @click="invoke(scope.row.id)"/>
        </template>
      </el-table-column>
      <!--<el-table-column v-if="formThead.merchantTotalMoney" align="center" label="商家总金额">-->
      <!--<template slot-scope="scope">-->
      <!--<span>{{ scope.row.merchantTotalMoney }}</span>-->
      <!--</template>-->
      <!--</el-table-column>-->
      <!--<el-table-column v-if="formThead.merchantRevenue" align="center" label="商家收入金额">-->
      <!--<template slot-scope="scope">-->
      <!--<span>{{ scope.row.merchantRevenue }}</span>-->
      <!--</template>-->
      <!--</el-table-column>-->
      <!--<el-table-column v-if="formThead.merchantExpenditure" align="center" label="商家支出金额">-->
      <!--<template slot-scope="scope">-->
      <!--<span>{{ scope.row.merchantExpenditure }}</span>-->
      <!--</template>-->
      <!--</el-table-column>-->
      <!--<el-table-column v-if="formThead.status" align="center" label="状态">-->
      <!--<template slot-scope="scope">-->
      <!--<span>{{ scope.row.status }}</span>-->
      <!--</template>-->
      <!--</el-table-column>-->
      <!--<el-table-column v-if="formThead.phone" align="center" label="电话">-->
      <!--<template slot-scope="scope">-->
      <!--<span>{{ scope.row.phone }}</span>-->
      <!--</template>-->
      <!--</el-table-column>-->

      <el-table-column align="center" label="操作" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <content_details :row_data="scope.row" @getLists="getLists"/>
          <editPage :row_data="scope.row" @getLists="getLists"/>
          <el-button type="danger" icon="el-icon-delete" circle title="删除" class="buttoncss" @click="del(scope.row.id)"/>
        </template>
      </el-table-column>
    </el-table>

    <div class="pagination-container">
      <el-pagination :current-page="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.limit" :total="total" background layout="total, sizes, prev, pager, next, jumper" @size-change="handleSizeChange" @current-change="handleCurrentChange"/>
    </div>
  </div>
</template>

<script>
import elDragDialog from '@/directive/el-dragDialog' // base on element-ui
import { getList, del, invoke, forbidden } from '@/api/merchant/merchant'
import store from '@/store'
import waves from '@/directive/waves' // 水波纹指令
import addPage from './addPage'
import editPage from './editPage'
import content_details from './content_details'
export default {
  name: 'DragDialogDemo',
  directives: {
    elDragDialog,
    waves
  },
  components: { addPage, editPage, content_details },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: null,
      listLoading: true,
      listQuery: {
        id: undefined,
        merchantName: undefined,
        adminAccount: undefined,
        adminPassword: undefined,
        paymentCode: undefined,
        auditStatus: undefined,
        merchantTotalMoney: undefined,
        merchantRevenue: undefined,
        merchantExpenditure: undefined,
        status: undefined,
        phone: undefined,
        page: 1,
        limit: 20
      },
      formThead: {
        id: true,
        merchantName: true,
        adminAccount: true,
        adminPassword: true,
        paymentCode: true,
        auditStatus: true,
        merchantTotalMoney: true,
        merchantRevenue: true,
        merchantExpenditure: true,
        status: false,
        phone: false
      }
    }
  },
  created() {
    this.getLists()
  },
  methods: {
    invoke(id) {
      invoke(store.getters.token, { id: id, index: 'index' }).then(res => {
        this.$message({
          message: '启用成功',
          type: 'success'
        })
        this.getLists()
      })
    },
    forbidden(id) {
      forbidden(store.getters.token, { id: id, index: 'index' }).then(res => {
        this.$message({
          message: '禁用成功',
          type: 'success'
        })
        this.getLists()
      })
    },
    getLists() {
      this.listLoading = true
      getList(store.getters.token, this.listQuery).then(response => {
        this.list = response.data.list.data
        this.total = response.data.list.total
        this.listLoading = false
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getLists()
    },
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.getLists()
    },
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.getLists()
    },
    del(id) {
      this.$message.info('正在删除' + id)
      del(store.getters.token, { id: id }).then(res => {
        this.$message.info('已经删除' + id)
        this.getLists()
      })
    }
  }
}
</script>
